/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package forense.classes;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Jessy
 */
public class LevantarServicio extends Thread {

    private String cmd;

    public LevantarServicio(String comando) {
        this.cmd = comando;
    }

    /**
     * Envia comandos a la consola de windows no imprime los resultados de la
     * operacion utilizar para levantar servicios
     */
    public void enviarComandoConsolaWindows(String comando) {
        OutputStream stdin = null;
        InputStream stdout = null;
        InputStream stderr = null;
        //System.out.println(""+comando);
        String line = comando;
        try {
            Process process = Runtime.getRuntime().exec("cmd.exe");
            stdin = process.getOutputStream();
            stdout = process.getInputStream();
            stderr = process.getErrorStream();
            stdin.write(line.getBytes());
            stdin.flush();
            stdin.close();

            BufferedReader brCleanUp = new BufferedReader(new InputStreamReader(stdout));
            while ((comando = brCleanUp.readLine()) != null) {
                System.out.println(comando);
            }
            brCleanUp = new BufferedReader(new InputStreamReader(stderr));
            while ((comando = brCleanUp.readLine()) != null) {
                System.out.println(comando);
            }
        } catch (IOException ex) {
            Logger.getLogger(LevantarServicio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void run() {
        //System.out.println("ejecutar: " + cmd);
        enviarComandoConsolaWindows(cmd);
    }
}
